package com.open.cloud.log.dto;

import com.github.structlog4j.IToLog;
import com.open.cloud.log.util.TraceUtil;
import lombok.Builder;
import lombok.Data;

import java.util.Optional;

/**
 * @author kong
 * @date 2021/4/30
 * blog: http://blog.kongyin.ltd
 */
@Data
@Builder
public class LogEntry implements IToLog {
    private String transId;
    private String path ;
    private String clazz ;
    private String method ;
    private String token ;
    private String username ;
    private String msg ;
    private String error ;


    @Override
    public Object[] toLog() {
        return new Object[] {
                "transId",  Optional.ofNullable(TraceUtil.getTrace()).orElse(""),
                "path",Optional.ofNullable(path).orElse(""),
                "clazz",Optional.ofNullable(clazz).orElse(""),
                "method",Optional.ofNullable(method).orElse(""),
                //TODO 添加token 及 username
                //"token" , Optional.ofNullable(TokenUtil.getToken()).orElse("") ,
                //"username", Optional.ofNullable(SysUserUtil.getLoginAppUser()).orElse(new LoginAppUser()).getUsername(),
                "msg" , Optional.ofNullable(msg).orElse(""),
                "error",Optional.ofNullable(error).orElse("")

        };
    }
}
